from functools import cached_property

from webutils.layers.managers import JsonMixin
from webutils.layers.managers.redis import HeartBeatMixin, HashMixin, ListMixin

from .base import BaseManager


class RoomState(JsonMixin, HashMixin, BaseManager):
    @cached_property
    def hash_key(self):
        return self.get_redis_key('mod', self.room_id)


class RoomStateHistory(JsonMixin, ListMixin, BaseManager):
    required_context = ['room_id', 'state_key']

    @cached_property
    def list_key(self):
        return self.get_redis_key('mod', 'his', self.room_id, self.state_key)


class RoomHeartbeat(HeartBeatMixin, BaseManager):
    @cached_property
    def heartbeat_key(self):
        return self.get_redis_key('heartbeat', self.room_id)
